using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using distrilan;


public partial class index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //la pagina deve essere sempre ricaricada da server anche quando si fa click sull'indietro del browser
        Response.Cache.SetNoStore();

        //vedo se devo fare il redirect
        if (hfRedirect.Value != "")
        {
            String value = hfRedirect.Value;
            //se era stato premuto un 13(invio) e si voleva effettuare la ricerca allora faccio il redirect
            if (value == "13")
                Response.Redirect("visualizzaArticoli.aspx?ricerca=" + txtBoxRicercaHome.Text);
        }
      
        //messaggio di benvenuto per l'utente
        SiteUser us = (SiteUser)HttpContext.Current.Session["SiteUser"];
        if (us != null)
        {
            lblUsername.Visible = true;
            lblUsername.Text = "Benvenuto: " + distrilan.SiteUser.getUser().Username;
        }
    }

    ///// <summary>
    ///// 
    ///// </summary>
    ///// <param name="sender"></param>
    ///// <param name="e"></param>
    //protected void textChanged(object sender, EventArgs e)
    //{
    //    if (txtBoxRicercaHome.Text.Length != 0)
    //        Server.Transfer("visualizzaArticoli.aspx?ricerca=" + txtBoxRicercaHome.Text);
    //}

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void log_out(object sender, EventArgs e)
    {
        distrilan.SiteUser.Exit();
        //Server.Transfer("index.aspx");
        Response.Redirect("index.aspx");
    }

    /// <summary>
    /// effettua la login
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (distrilan.SiteUser.Login(txtBoxLogin.Text, txtBoxPwd.Text, false) == true)
            Carrello.ControllaCarrello();
    }


    protected void lnkBtntxtBoxRicercaHome_Click(object sender, EventArgs e)
    {
        String redirect = "visualizzaArticoli.aspx?ricerca=" + txtBoxRicercaHome.Text;
        //Server.Transfer(redirect);
        Response.Redirect(redirect);
    }
}